package com.mjh.manager;

import java.util.HashMap;
import org.apache.log4j.Logger;
import com.mjh.bean.ArticleDetail;
import com.mjh.comm.page.Pager;
import com.mjh.config.GlobalConfig;
import com.mjh.dao.ArticleDetailDAO;

public class ArticleDetailManager {

	public static Logger log = Logger.getLogger(ArticleDetailManager.class);
	
	private ArticleDetailDAO dao = new ArticleDetailDAO();
	
	public int addArticleDetail(ArticleDetail articleDetail){
		return dao.insert(articleDetail);
	}
	
	public int editArticleDetail(ArticleDetail articleDetail){
		return dao.update(articleDetail);
	}
	
	public int delDetail(ArticleDetail articleDetail){
		return dao.delete(articleDetail.getId());
	}

	public int delDetailByArticle(int articleId){
		return dao.deleteByArticle(articleId);
	}
	
	public Pager<ArticleDetail> listForPage(int articleId, int pagerNo){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		Pager<ArticleDetail> pager = new Pager<ArticleDetail>();
		pager.setPageNo(pagerNo);
		pager.setPageSize(GlobalConfig.getSysConfig().getArticleDetailPageSize());
		parameter.put("pageStart", pager.getStartNo());
		parameter.put("pageSize", pager.getPageSize());
		parameter.put("articleId", articleId);
		pager.setTotalNum(dao.selectCount(articleId));
		pager.setPageData(dao.selectForPage(parameter));
		return pager;
	}

	public Pager<ArticleDetail> listByArticleId(int articleId){
		Pager<ArticleDetail> pager = new Pager<ArticleDetail>();
		pager.setPageData(dao.selectByArticleId(articleId));
		return pager;
	}
	
	public int getTotalRecordNum(int articleId){
		return dao.selectCount(articleId);
	}	
}
